package com.jubaopen.service;

import com.jubaopen.bean.SmsRecord;
import com.jubaopen.dao.SmsRecordDAO;
import com.jubaopen.sms.MsgSend;

public class SmsService {

	private SmsRecordDAO smsRecordDAO;
	private MsgSend msgSend; 

	public void setSmsRecordDAO(SmsRecordDAO smsRecordDAO) {
		this.smsRecordDAO = smsRecordDAO;
	}
	
	public void setMsgSend(MsgSend msgSend) {
		this.msgSend = msgSend;
	}


	public void doSendSmsCode(SmsRecord entry,String smsContent) {
		SmsRecord exEntry = smsRecordDAO.getSmsCode(entry.getMobile());
		if(exEntry != null){
			entry.setId(exEntry.getId());
			smsRecordDAO.updateById(entry);
		}else{
			smsRecordDAO.add(entry);
		}
		entry.setContent(smsContent);
		msgSend.sendQueue.push(entry);
		
	}
	
	public void doSendSms(SmsRecord entry) {
		if (!"".equals(entry.getMobile())) {
			msgSend.sendQueue.push(entry);
		}
		smsRecordDAO.add(entry);
	}
	public SmsRecord getSmsCode(String mobile) {
		return smsRecordDAO.getSmsCode(mobile);
	}

	public int updateBySeqNo(SmsRecord entry){
		return smsRecordDAO.updateBySeqNo(entry);
	}
	
	public int updateById(SmsRecord entry){
		return smsRecordDAO.updateById(entry);
	}

	public SmsRecord queryBySeqNo(String seqNo) {
		return smsRecordDAO.getOneBySeqNo(seqNo);
	}
	
	public SmsRecord queryByReqId(String reqId) {
		return smsRecordDAO.getOneByReqId(reqId);
	}
}
